package com.example.demospringmybatisplus.service;

import com.example.demospringmybatisplus.entity.Invoice;
import com.example.demospringmybatisplus.enums.InvoiceActionEnum;
import com.example.demospringmybatisplus.listener.InvoiceActionListenerManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 发票服务
 *
 * @author huahua
 * @DATE 2025/8/3
 **/
@Service
public class InvoiceService {
    @Autowired
    private InvoiceActionListenerManager invoiceActionListenerManager;

    public void updateInvoice(Invoice invoice,String invoiceStatus) {
        if(InvoiceActionEnum.CREATE.toString().equals(invoiceStatus)){
            invoiceActionListenerManager.notify(InvoiceActionEnum.CREATE, invoice);
        }

        if(InvoiceActionEnum.UPDATE.toString().equals(invoiceStatus)){
            invoiceActionListenerManager.notify(InvoiceActionEnum.UPDATE, invoice);
        }

        if(InvoiceActionEnum.ADD_RETRIEVE.toString().equals(invoiceStatus)){
            invoiceActionListenerManager.notify(InvoiceActionEnum.ADD_RETRIEVE, invoice);
        }

        if(InvoiceActionEnum.RELEASE.toString().equals(invoiceStatus)){
            invoiceActionListenerManager.notify(InvoiceActionEnum.RELEASE, invoice);
        }

        if(InvoiceActionEnum.CANCEL.toString().equals(invoiceStatus)){
            invoiceActionListenerManager.notify(InvoiceActionEnum.CANCEL, invoice);
        }
    }
}
